var KONFIGURATOR_BASE_GALLERY = {ldelim}
	praefix: '',
	description: '',
	err_msg: '',
	value: '-1',
	thmb_nochoose: window.KONFIGURATOR_IMGPATH_THMB + 'no-choose_thumb.jpg',

  init: function() {ldelim}
  	//$D('[base] init .. '+this.praefix); 
{if $FORM_ACTION == true}
  	KONFIGURATOR_objects.push(this.praefix.toUpperCase());
  	this.addChooseThmbContainer();

{/if}
  	$('#gallery_'+this.praefix+' div.thmb').click($.proxy(this.onChooseThmb, this));
  	$('#gallery_'+this.praefix+' div.button-select').click($.proxy(this.onChange, this));
  {rdelim},

{if $FORM_ACTION == true}
  addChooseThmbContainer: function() {ldelim}
 		var c = $('#gallery ul.ad-thumb-list').children('li').length;
 		$('#gallery ul.ad-thumb-list').append(
				'<li id="thmb_'+this.praefix.toUpperCase()+'" rel="konfigurator_option">'
			+ 	'<a class="thumb thumb'+c+'" href="">'
			+ 		'<img alt="'+this.description+'" class="image'+c+'" src="/'+this.thmb_nochoose+'" style="opacity: 0.6;">'
			+ 	'</a>'
			+	'</li>'
		);
		
		$('#thmb_'+this.praefix.toUpperCase()).click(KONFIGURATOR_clickOnThmb);
  
  {rdelim},
{/if}

  loadFirstValue: function() {ldelim}
  	var id_long = $($('#gallery_'+this.praefix+' ul li').get(0)).find('img').attr('id');
		var	id = id_long.substr(id_long.indexOf('_thmb_')+6);
		this.loadValue(id);
  {rdelim},

  loadValue: function(id) {ldelim}
  	var imgId = $('#gallery_'+this.praefix+'_thmb_'+id).parents('div.thmb');
  	this.onChooseThmb({ldelim}currentTarget: imgId.get(0){rdelim});
{if $FORM_ACTION == true}
  	this.onChange();
{/if}
  {rdelim},
{literal}  
  onChooseThmb: function(ev) {
		$('#gallery_'+this.praefix+' li div.thmb').removeClass('active');
		$(ev.currentTarget).addClass('active');
		
  	var id =		$(ev.currentTarget).find('img').attr('id');
  	var src =		$(ev.currentTarget).find('img').attr('src').split('/');
  	var name =	$(ev.currentTarget).find('p').html();
  	var descr =	$(ev.currentTarget).find('span').html();

  	id =  id.substr(('gallery_'+this.praefix+'_thmb_').length)
  	src = src[src.length-1];
  	
  	var imgSrc_thmb = $('#gallery_'+this.praefix+' img[name=thmb-select]').attr('src').split('/');
  	imgSrc_thmb[imgSrc_thmb.length-1] = src;

  	$('#gallery_'+this.praefix+' div[name=id-select]').html(id);
  	$('#gallery_'+this.praefix+' div[name=src-select]').html(src);
  	$('#gallery_'+this.praefix+' span[name=name-select]').html(name);
  	$('#gallery_'+this.praefix+' p[name=descr-select]').html(descr);
  	$('#gallery_'+this.praefix+' img[name=thmb-select]').attr({'src': imgSrc_thmb.join('/')});
  	this.onChooseThmb_form(ev);
  },
{/literal}

{if $FORM_ACTION == true}
{literal}
  onChange: function() {
  	var praefix_upper = this.praefix.toUpperCase();
    this.value = $('#gallery_'+this.praefix+' div[name=id-select]').html();
    var img_name = $('#gallery_'+this.praefix+' div[name=src-select]').html();
		$('.container_popup_layer .btn_close').click();

  	$('#thmb_'+praefix_upper+' a').attr({'href': window.KONFIGURATOR_IMGPATH_POPUP+praefix_upper+'/'+img_name});
  	$('#thmb_'+praefix_upper+' img').attr({'src': window.KONFIGURATOR_IMGPATH_THMB+praefix_upper+'/'+img_name});
  	$('#thmb_'+praefix_upper+'').show();
  	
  	$('#'+praefix_upper).val(this.value);
  	$('#'+praefix_upper).change();
  	
  	$('div[tmpl='+praefix_upper+'] span.name_option').html($('#gallery_'+this.praefix+' span[name=name-select]').html());
  },
  
  evalValue: function() {
  	if (this.value == '-1')
	  		return {'status':'failed', 'msg': (this.err_msg == '' ? 'Bitte w\u00E4hlen Sie ein '+this.description+' aus' : this.err_msg)};
  	else
  		return {'status':'okay'};
	},
	
	onChooseThmb_form: function(ev) {
		$('#gallery_'+this.praefix+' div.button-select').show();
	}
	
{/literal}
{else}
  onChooseThmb_form: function(ev) {ldelim} {rdelim}
{/if}

{rdelim};